package com.ddtech.framework.system.service;

import com.ddtech.framework.system.model.SysUser;
import com.ddtech.framework.system.model.bo.SysVrUserBo;
import com.ddtech.framework.system.model.vo.UserInfoVo;
import com.ddtech.framework.system.service.dto.UserDTO;
import com.ddtech.framework.system.service.dto.UserQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Apache License
 * @date 2018-11-23
 */
@CacheConfig(cacheNames = "user")
public interface UserService {

    /**
     * get
     * @param id
     * @return
     */
    @Cacheable(key = "#p0")
    UserDTO findById(String id);

    /**
     * create
     * @param resources
     * @return
     */
    @CacheEvict(allEntries = true)
    UserDTO create(SysUser resources);

    /**
     * update
     * @param resources
     */
    @CacheEvict(allEntries = true)
    void update(SysUser resources);

    /**
     * delete
     * @param id
     */
    @CacheEvict(allEntries = true)
    void delete(String id);

    /**
     * findByName
     * @param userName
     * @return
     */
    @Cacheable(key = "'loadUserByUsername:'+#p0")
    UserDTO findByName(String userName);

    SysUser  findByAccount(String userName);

    SysUser  findByNickname(String userName);

    SysUser findByEmail(String  email);


    /**
     * 修改密码
     * @param username
     * @param encryptPassword
     */
    @CacheEvict(allEntries = true)
    int updatePass(String username, String encryptPassword);

    /**
     * 修改头像
     * @param file
     */
    @CacheEvict(allEntries = true)
    void updateAvatar(MultipartFile file);

    /**
     * 修改邮箱
     * @param username
     * @param email
     */
    @CacheEvict(allEntries = true)
    void updateEmail(String username, String email);

    @Cacheable(keyGenerator = "keyGenerator")
    Object queryAll(UserQueryCriteria criteria, Pageable pageable);

    Object queryUserAll(UserQueryCriteria criteria, Pageable pageable);

    Object findTransferUsers(UserQueryCriteria criteria);

    /**
     * 导入用户信息
     * @param file
     * @param deptId
     * @param passWord
     * @return
     */
    @CacheEvict(allEntries = true)
    boolean userImport(String deptId,MultipartFile file, String passWord);


    /**
     * 导入VR用户信息
     * @param list
     * @return
     */
    @CacheEvict(allEntries = true)
    boolean vrUserImport(List<SysVrUserBo> list);

    @CacheEvict(allEntries = true)
    void updateAvatarV2(String url);

    /**
     * 修改个人信息
     * @param userInfoVo
     */
    @CacheEvict(key = "'loadUserByUsername:'+#userInfoVo.userName")
    void updateUserInfo(UserInfoVo userInfoVo);

    void downLoadUserTel(HttpServletResponse response);
}
